#include <avr/io.h>
#include <util/delay.h>

#include "OM10B.h"
#include "lcd.h"

int main()
{
char temp;

static int delta_x,delta_y,pdelta_x,pdelta_y,temp16_t;
OM10B_init(); 


//OM10B_force_active(ACTIVATE);
OM10B_write(0x12,0x20);

/////////////////////////////////////////////////////

   //Initialize LCD module
   LCDInit(LS_BLINK|LS_ULINE);

   //Clear the screen
   LCDClear();

   //Simple string printing
   LCDWriteString("Congrats ");

   //A string on line 2
   LCDWriteStringXY(0,1,"Akshit ");


   _delay_ms(1000);

	//Clear the screen
   LCDClear();

/////////////////////////////////////////////////////




while(1)
{

temp=OM10B_read(0x02);

if( temp&0x80 )
	{
		temp=OM10B_read(0x03);
		delta_x+=temp;
		temp=OM10B_read(0x04);
		delta_y+=temp;
	}
	else{
		
		if( (pdelta_x!=delta_x) || (pdelta_y!=delta_y) )
	{
	pdelta_x=delta_x;
	pdelta_y=delta_y;
	LCDClear();
	temp16_t=delta_x;
		if(temp16_t<0)
		{ temp16_t=(~temp16_t)+1;
		  LCDWriteStringXY(0,0,"X:-");
		}else
		{	LCDWriteStringXY(0,0,"X:+"); }
		
	LCDWriteIntXY(3,0,temp16_t,5);
	temp16_t=delta_y;
		if(temp16_t<0)
		{ temp16_t=(~temp16_t)+1;
		  LCDWriteStringXY(0,1,"Y:-");
		}else
		{ LCDWriteStringXY(0,1,"Y:+"); }
		
	LCDWriteIntXY(3,1,temp16_t,5);
		}
	
	}

}

}
